﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once

#include "GcmpDevService.h"
#include "OwnerPtr.h"
#include "GbmpNew.h"
#include <string>
#include <fstream>

typedef unsigned char byte;

class MD5;

namespace gcmp
{
    /// \brief 计算MD5值接口
    class GCMP_DEV_SERVICE_EXPORT GcmpMD5 
    {
    public:
        /// \brief 默认构造函数
        GcmpMD5();

        /// \brief 带参构造函数
        /// \param input 输入内存地址
        /// \param length 长度信息
        GcmpMD5(const void* input, size_t length);

        /// \brief 带参构造函数
        /// \param str 输入字符串
        GcmpMD5(const std::string& str);

        /// \brief 带参构造函数
        /// \param in 输入流
        GcmpMD5(std::ifstream& in);

        ~GcmpMD5();

    public:
        /// \brief 向MD5对象内添加内存块
        /// \param input 输入内存地址
        /// \param length 长度信息
        void Update(const void* input, size_t length);

        /// \brief 向MD5对象内添加字符串
        /// \param str 输入字符串
        void Update(const std::string& str);

        /// \brief 向MD5对象内添加输入流
        /// \param in 输入流
        void Update(std::ifstream& in);

        /// \brief 计算MD5码，并返回指向它的指针
        /// \return byte* 指向MD5码的指针
        const byte* Digest();

        /// \brief 计算MD5码，并返回其对应的字符串
        /// \return std::string MD5码对应的字符串
        std::string ToString();

        /// \brief 重置
        void Reset();

    public:
        /// \brief 计算文件的MD5值
        /// \param filePath 文件绝对路径
        /// \return std::wstring 文件的MD5值字符串
        static std::wstring ComputeFileMD5Value(const std::wstring filePath);

    private:
        OwnerPtr<MD5> m_oMd5;
    };
}